package com.guw.TestThread;

//静态代理模式
//真实对象和代理对象都要实现同一个接口
//代理对象要代理真实角色
//优点:代理对象可以做很多真实对象做不了的事情,真实对象可以专注自己的事情
public class StaticProxy {
    public static void main(String[] args) {
       /* WeddingCompany weddingCompany = new WeddingCompany(new You());
        weddingCompany.HappyMarry();*/
       You you = new You();
       new Thread( ()-> System.out.println("123,开始")).start();
       new WeddingCompany(you).HappyMarry();
    }
}

interface Marry{
    void HappyMarry();
}

class You implements Marry{
    @Override
    public void HappyMarry() {
        System.out.println("你很开心");
    }
}

class WeddingCompany implements Marry{
    //代理角色
    private Marry target;
    //真实角色通过构造方法传入
    public WeddingCompany(Marry target) {
        this.target = target;
    }

    @Override
    public void HappyMarry() {
        before();
        this.target.HappyMarry();
        after();
    }

    private void before() {
        System.out.println("准备工作");
    }

    private void after() {
        System.out.println("收尾工作");
    }
}